package com.yunhui.admin;

import org.springframework.security.core.context.SecurityContextHolder;

import com.yunhui.admin.model.AdminUserDateils;
import com.yunhui.entity.YCAdmin;


/**
 * 获取当前用户登录的信息
 * @author Administrator
 *
 */
public class AdminUserContext {
	
	public static YCAdmin getUser() {
		if (SecurityContextHolder.getContext().getAuthentication() == null) {
			return null;
		}

		Object user = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		if (user != null && user instanceof AdminUserDateils) {
			AdminUserDateils userDetails = (AdminUserDateils) user;
			if (userDetails != null) {
				return userDetails.getyCAdmin();
			}
		}

		return null;
	}
	

	public static String getAccount() {
		YCAdmin yCAdmin = AdminUserContext.getUser();
		if (yCAdmin == null) {
			return "";
		}
		return yCAdmin.getAdminAccount();
	}

	public static int getUserId() {
		YCAdmin yCAdmin = AdminUserContext.getUser();
		if (yCAdmin == null) {
			return -1;
		}
		return yCAdmin.getId();
	}
}
